﻿using System;
using System.Collections.Generic;
using System.Text;
using WindowsInput;
using WindowsInput.Native;
using System.Net;
using System.Net.Security;
using System.Threading;
using System.Diagnostics;
using System.Windows.Forms;

namespace Tornado
{
    public class SignalPowerpoint : SignalProcesser
    {
        KeyboardSimulator keyboard = new KeyboardSimulator();
        MouseSimulator mouse = new MouseSimulator();

        bool isLazerOn = false;

        public override SignalCodes Code
        {
            get { return SignalCodes.PRESENTATION; }
        }
        public override void Process(ref SignalPacket p)
        {
            switch ((PresentationExCode)p.ExtensionCode)
            {
                case PresentationExCode.Control:
                    if (WinProcess.forcePowerpoint())
                    {
                        keyboard.KeyPress((VirtualKeyCode)p.Argument[0]);
                    }
                    break;
                case PresentationExCode.Lazer:
                    if (((int)p.Argument[0] == 1) && (!isLazerOn)) 
                    {
                        //New way, only apply for powerpoint
                        //keyboard.KeyDown(VirtualKeyCode.CONTROL);
                        //mouse.LeftButtonDown();
                        System.Diagnostics.Process.Start(Application.ExecutablePath, "lazer " + (int)p.Argument[0]);
                        isLazerOn = true;
                    }
                    else if (((int)p.Argument[0] == 0) && (isLazerOn))
                    {
                        ////New way, only apply for powerpoint
                        //keyboard.KeyUp(VirtualKeyCode.CONTROL);
                        //mouse.LeftButtonUp();
                        mouse.MiddleButtonClick();
                        isLazerOn = false;
                    }
                    break;
                case PresentationExCode.GoTo:
                    if (WinProcess.forcePowerpoint())
                    {
                        keyboard.TextEntry(BitConverter.ToInt32(p.Argument, 0).ToString());
                        keyboard.KeyPress(VirtualKeyCode.RETURN);
                    }
                    break;
            }
        }
    }
}
